package com.hz.ruoyiequipment.warning.controller;

import com.hz.ruoyiequipment.warning.domain.AgrAlertType;
import com.hz.ruoyiequipment.warning.domain.vo.AgrAlertLinkResultVo;
import com.hz.ruoyiequipment.warning.domain.vo.AgrAlertLinkVo;
import com.hz.ruoyiequipment.warning.service.AgrAlertLinkService;
import com.hz.ruoyiequipment.warning.service.AgrAlertTypeService;
import com.hz.ruoyiequipment.warning.service.SmsService;
import com.hz.ruoyiequipment.warning.service.impl.ThresholdRedisService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName AgrAlertLinkController
 * @Description 设备联动控制器
 * @Author 陈萝瑶
 * @Date 2025/3/10 12:08
 */
@RestController
@RequestMapping("/warning")
public class AgrAlertLinkController {

    @Autowired
    private AgrAlertLinkService agrAlertLinkService;

    @Autowired
    private AgrAlertTypeService agrAlertTypeService;
    @Autowired
    private SmsService smsService;


    @GetMapping("/getByBreedId")
    public R<List<AgrAlertLinkVo>> getByBreedId(Long breedId,Long plotsId){
        return R.ok(agrAlertLinkService.getByBreedId(breedId,plotsId));
    }

    @GetMapping("/getByBatchName")
    public R<List<AgrAlertLinkVo>> getByBatchName(Long batchId){
        return R.ok(agrAlertLinkService.getByBatchName(batchId));
    }

    @GetMapping("/getSourceEquipment")
    public R<List<AgrAlertLinkVo>> getSourceEquipment(Long breedId, Long batchId){
        return R.ok(agrAlertLinkService.getSourceEquipment(breedId,batchId));
    }

    @GetMapping("/getTargetEquipment")
    public R<List<AgrAlertLinkVo>> getTargetEquipment(Long breedId, Long batchId){
        return R.ok(agrAlertLinkService.getTargetEquipment(breedId,batchId));
    }

    @GetMapping("/getFiled")
    public R<List<AgrAlertType>> getFiled(){
        return R.ok(agrAlertTypeService.list());
    }

    @GetMapping("/getAllByBreedId")
    public R<List<AgrAlertLinkResultVo>> getAllByBreedId(Long breedId){
        return R.ok(agrAlertLinkService.getAllByBreedId(breedId));
    }

    @GetMapping("/getTriggerByBreedId")
    public R<List<AgrAlertLinkResultVo>> getTriggerByBreedId(Long breedId){
        return R.ok(agrAlertLinkService.getTriggerByBreedId(breedId));
    }

    @GetMapping("/getBatchByPlotsId")
    public R<List<AgrAlertLinkVo>> getBatchByPlotsId(Long plotsId,Integer batchStatus){
        return R.ok(agrAlertLinkService.getBatchByPlotsId(plotsId,batchStatus));
    }

    @PostMapping("/insertField")
    public AjaxResult insertField(@RequestBody AgrAlertLinkResultVo agrAlertLinkResultVo)
    {
        return AjaxResult.success(agrAlertLinkService.insertAgrAlertThresholdField(agrAlertLinkResultVo));
    }

    @PostMapping("/insertFieldLink")
    public AjaxResult insertFieldLink(@RequestBody AgrAlertLinkResultVo agrAlertLinkResultVo)
    {
        return AjaxResult.success(agrAlertLinkService.insertFieldLink(agrAlertLinkResultVo));
    }

    @PostMapping("/updateAgrAlertEquipLink")
    public AjaxResult updateAgrAlertEquipLink(@RequestBody AgrAlertLinkResultVo agrAlertLinkResultVo)
    {
        return AjaxResult.success(agrAlertLinkService.updateAgrAlertEquipLink(agrAlertLinkResultVo));
    }

    @GetMapping("/updateAgrAlertField")
    public AjaxResult updateAgrAlertField(Long breedId,Long batchId)
    {
        return AjaxResult.success(agrAlertLinkService.updateAgrAlertField(breedId, batchId));
    }

    @GetMapping("/delTrigger")
    public AjaxResult delTrigger(Long fieldId)
    {
        return AjaxResult.success(agrAlertLinkService.delTrigger(fieldId));
    }

    //短信
    @PostMapping("/sendMsg")
    public AjaxResult snedMsg(@RequestParam(value = "phoneNumber") String phoneNumber, @RequestParam(value = "code") String code){
        return AjaxResult.success(smsService.sendVerificationCode(phoneNumber,code));
    } /**
     * 根据设备id获取设备联动信息
     * @param sourceId 设备id
     * @return
     */
    @PostMapping("/getAllBySourceId")
    public AjaxResult getAllBySourceId(@RequestParam(value = "sourceId",required = false) Long sourceId){

        return AjaxResult.success(agrAlertLinkService.getAllBySourceId(sourceId));
    }

}
